package com.apexedu.portal.service.impl;
/**
 * 管理员模板控�?
 * @author zhuzhonglei
 * @time 2009-11-20
 */

import com.apexedu.biz.Const;
import com.apexedu.framework.service.impl.AbstractBaseServiceSupport;
import com.apexedu.framework.util.DBUtil;
import com.apexedu.framework.util.Pager;
import com.apexedu.framework.util.SeqFactory;
import com.apexedu.identity.action.IdLoginAction;
import com.apexedu.portal.action.FrontdesknewsbaseAction;
import com.apexedu.portal.entity.TFrontdeskNews;
import com.apexedu.sys.util.BusinessLogUtil;
import com.apexedu.util.StringUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("frontdeskNewsbaseService")
public class FrontdesknewsbaseServiceImpl extends AbstractBaseServiceSupport {

    private static final Logger logger = Logger.getLogger(FrontdesknewsbaseServiceImpl.class);

    public List<?> list(Object obj, Pager pager) throws Exception {
        long c=DBUtil.count("select count(*) as c from t_frontdesk_news t ");
        pager.setTotalRows(c);
        String sql="select wid,(select code from t_db where wid=t.code) as code,lmmc,(select zdmc from T_SYS_CODE where zdbm=t.weiz and zdlb='news_wz' ) as weiz,shuom,state from t_frontdesk_news t";
        List<TFrontdeskNews> list = DBUtil.queryPageBeanList(pager,sql, TFrontdeskNews.class);
        return list;
    }

    @Override
    public void saveOrUpdate(Object myaction) throws Exception {
        FrontdesknewsbaseAction action = (FrontdesknewsbaseAction) myaction;
        TFrontdeskNews tfrontdesknews = action.getTfrontdesknews();
       if (tfrontdesknews != null) {
            if (StringUtil.isNotBlank(tfrontdesknews.getWid())) {
                baseDao.updateNotNull(tfrontdesknews);
                BusinessLogUtil.log(action.getUserloginid(), Const.CZDX_T_FRONTDESK_NEWS, Const.LOG_ACTION_UPDATE,
                        IdLoginAction.getIpAddr(action.getRequest()), "修改前台新闻配置");
            } else {
                tfrontdesknews.setWid(SeqFactory.getNewSequenceAlone());
                baseDao.save(tfrontdesknews);
                BusinessLogUtil.log(action.getUserloginid(), Const.CZDX_T_FRONTDESK_NEWS, Const.LOG_ACTION_SAVE,
                        IdLoginAction.getIpAddr(action.getRequest()),"新增前台新闻配置");
            }
        }
    }

    @Override
    public void load(Object myaction) throws Exception {
        FrontdesknewsbaseAction action = (FrontdesknewsbaseAction) myaction;
        String wid = action.getWid();
        TFrontdeskNews tfrontdesknews = DBUtil.queryBean("select * from T_FRONTDESK_NEWS t where t.wid = ?", TFrontdeskNews.class, wid);
        action.setTfrontdesknews(tfrontdesknews);
    }

    @Override
    public boolean remove(Object myaction) throws Exception {
        return false;
    }
}
